<?php

namespace app\common\model\Project;

use think\Model;
// 引用软删除
use traits\model\SoftDelete;

class Order extends Model
{
    protected $table = 'pre_project_order';

    //软删除
    use SoftDelete;
    protected $deleteTime = 'deletetime';

    // 自动写入时间
    protected $autoWriteTimestamp = false;

    // 创建时间 => 注册时间
    protected $createTime = 'createtime';

    // 更新时间
    protected $updateTime = false;

    protected $append = [
        'status_text'
    ];

    // 关联查询
    public function project()
    {
        return $this->belongsTo('app\common\model\Project\Project', 'projectid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    // 关联查询
    public function user()
    {
        return $this->belongsTo('app\common\model\User\User', 'userid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    // 关联查询
    public function address()
    {
        return $this->belongsTo('app\common\model\User\Address', 'addrid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getStatusTextAttr($value, $data)
    {
        switch ($data['status']) {
            case 0:
                return '未接单';
                break;
            case 1:
                return '待付款';
                break;
            case 2:
                return '已付款';
                break;

            case 3:
                return '已完成';
                break;

            case -1:
                return '已撤销';
                break;

            case -2:
                return '申请撤销';
                break;

            case -3:
                return '被拒撤销';
                break;

            default:
                # code...
                break;
        }
    }
}
